//
//  MKHotThemeCell.swift
//  MOKOAnnounce
//
//  Created by 曹相召 on 2017/7/11.
//  Copyright © 2017年 cc.moko. All rights reserved.
//  热门专题 cell

import UIKit

class MKHotThemeCell: MKBaseTableViewCell ,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
    
    var collectionView:UICollectionView!
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.backgroundColor = UIColor.white
        self.contentView.backgroundColor = UIColor.white
        
        let layout:UICollectionViewFlowLayout = UICollectionViewFlowLayout.init()
        layout.minimumLineSpacing = 5
        layout.minimumInteritemSpacing = 5
        let width = (ScreenWidth - 10) / 3
        layout.itemSize = CGSize.init(width: width, height: width * 260 / 244)
        self.collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: layout)
        self.collectionView.showsHorizontalScrollIndicator = false
        self.collectionView.backgroundColor = UIColor.clear
        self.collectionView.delegate = self
        self.collectionView.dataSource = self
        self.collectionView.register(MKHotThemeSubCell.classForCoder(), forCellWithReuseIdentifier: "MKHotThemeSubCell")
        self.contentView.addSubview(self.collectionView)
    }
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 6
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell:MKHotThemeSubCell = collectionView.dequeueReusableCell(withReuseIdentifier: "MKHotThemeSubCell", for: indexPath) as! MKHotThemeSubCell
        return cell
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.collectionView.frame = self.contentView.bounds
        self.collectionView.contentInset = UIEdgeInsetsMake(8, 0, 8, 0)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

class MKHotThemeSubCell: UICollectionViewCell {
    var icon:UIImageView!
    var tip:UILabel!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor.white
        self.contentView.backgroundColor = UIColor.white
        
        self.icon = UIImageView.init()
        self.icon.image = UIImage.init(named: "newHome_hotActor_bottomBlack")
        self.icon.contentMode = .scaleAspectFill
        self.icon.clipsToBounds = true
        self.contentView.addSubview(self.icon)
        
        self.tip = UILabel.label(fontSize: 14, textColor: UIColorFromRGB(rgbValue: 0x333333, A: 1))
        self.tip.backgroundColor = UIColor.randomColor()
        self.tip.text = "#天下第一美女#"
        self.contentView.addSubview(self.tip)
        
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.icon.frame = self.contentView.bounds
        
        self.tip.sizeToFit()
        self.tip.frame = CGRect.init(x: 10, y: self.icon.bottom - 5 - self.tip.height, width: self.width - 10, height: self.tip.height)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
